package com.lcj.controller;

import com.lcj.vo.UserVo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.Errors;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.List;

@Controller
@RequestMapping("/user")
public class UserController {
    @RequestMapping("/regist")
    public String regist(@ModelAttribute("u") UserVo userVo, Errors errors, Model model, HttpServletRequest request)
    {
        Object cities1 = model.getAttribute("cities");
        System.out.println(cities1+"++");


        Object cities = request.getAttribute("cities");
        System.out.println(cities+"++");

        System.out.println("UserController.regist  uservo="+userVo);

        Object user = request.getAttribute("userVo");
        System.out.println(user+"++");
        if(errors.hasErrors())
        {
            System.out.println(errors);
            return "regist";
        }
        return "success";
    }

    @ModelAttribute("cities")
    public List<String> modelattr(){
        System.out.println("UserController.modelattr");
        List<String> list = Arrays.asList("中国", "南京", "江苏");
        return list;
    }
}
